/**
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 * 
 *         http://www.apache.org/licenses/LICENSE-2.0
 *         
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. Unless required by applicable law or
 * agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */
package org.rhok.pdx.ncn.application;

import java.util.LinkedList;
import java.util.Queue;

import org.rhok.pdx.ncn.datatypes.LocationData;
import org.rhok.pdx.ncn.listeners.MapPlotter.MapPlotterContext;
import org.rhok.pdx.ncn.listeners.TrackingLocationListener.LocationListenerContext;
import org.rhok.pdx.ncn.listeners.TrackingPhoneStateListener.PhoneStateListenerContext;
import org.rhok.pdx.ncn.listeners.WifiSignalTracker.WifiSignalTrackerContext;
import org.rhok.pdx.ncn.storage.NCNDatabaseManager;
import org.rhok.pdx.ncn.storage.NCNDatabaseManager.NCNDatabaseManagerContext;

import android.app.Activity;

import com.google.android.maps.MapView;

/**
 * Stores the state and all information or references that are used throughout the application.
 * @author pfritzsche
 */
public class ApplicationContext implements LocationListenerContext, NCNDatabaseManagerContext,
		PhoneStateListenerContext, WifiSignalTrackerContext, MapPlotterContext {
	
	private Queue<LocationData> locs = new LinkedList<LocationData>();
	private final Activity app;
	private final NCNDatabaseManager db;
	private int signalStrength;
	private int wifiStrength;
	private MapView mapView;
	
	/**
	 * Public constructor.
	 *
	 * @param app the main application object
	 */
	public ApplicationContext(Activity app) {
		this.app = app;
		this.db = new NCNDatabaseManager((NCNDatabaseManagerContext) this);
	}
	
	/**
	 * Signal strength setter. Used to update the phone's current cell signal strength.
	 *
	 * @param signalStrength the signal strength
	 */
	public void signalStrength(int signalStrength) { this.signalStrength = signalStrength; }
	
	/**
	 * Wifi signal strength setter. Used to update the phone's current wifi signal strength.
	 *
	 * @param wifiStrength the wifi strength
	 */
	public void wifiStrength(int wifiStrength) { this.wifiStrength = wifiStrength; }
	
	/**
	 * Map view.
	 *
	 * @param mapView the map view
	 */
	public void mapView(MapView mapView) { this.mapView = mapView; }
	
	/**
	 * Location data getter. Used to access the queue storing the phone's recent locations and
	 * signal strength information.
	 *
	 * @return the queue
	 */
	public Queue<LocationData> locs() { return locs; }
	
	/**
	 * Application getter.
	 * @return the main application object
	 */
	public Activity app() { return app; }
	
	/**
	 * Database getter.
	 * @return the object used to interact with the application's database
	 */
	public NCNDatabaseManager db() { return db; }
	
	/**
	 * Signal strength getter.
	 * @return the phone's current signal strength
	 */
	public int signalStrength() { return signalStrength; }
	
	/**
	 * Wifi signal strength getter.
	 * @return the phone's current wifi signal strength
	 */
	public int wifiStrength() { return wifiStrength; }
	
	/* (non-Javadoc)
	 * @see org.rhok.pdx.ncn.listeners.MapPlotter.MapPlotterContext#mapView()
	 */
	public MapView mapView() { return mapView; }
}
